<template>
  <div class="game-card">
    <div class="card-image-container">
      <div class="card-image" :style="{ backgroundImage: `url(${image})` }"></div>
    </div>
    <div class="card-content">
      <h3 class="card-title">{{ title }}</h3>
      <p class="card-description">{{ description }}</p>
      <div v-if="customAction" class="play-button" @click="handleAction">
        开始游戏
        <svg class="arrow-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
          <path d="M5 12H19M19 12L12 5M19 12L12 19" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
        </svg>
      </div>
      <a v-else :href="link" target="_blank" class="play-button">
        开始游戏
        <svg class="arrow-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
          <path d="M5 12H19M19 12L12 5M19 12L12 19" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
        </svg>
      </a>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const props = defineProps({
  title: {
    type: String,
    required: true
  },
  description: {
    type: String,
    required: true
  },
  image: {
    type: String,
    required: true
  },
  link: {
    type: String,
    required: false, // 不再是必需的，因为有些卡片可能使用customAction
    default: ''
  },
  customAction: {
    type: Function,
    required: false,
    default: null
  }
})

// 处理点击操作
function handleAction() {
  if (props.customAction && typeof props.customAction === 'function') {
    props.customAction();
  }
}

const hovered = ref(false)
</script>

<style scoped>
.game-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  display: flex;
  flex-direction: column;
  height: 100%;
  animation: slideUp 0.5s ease-out;
}

.game-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15);
}

.game-card:hover .card-image::before {
  opacity: 0;
}

.card-image-container {
  height: 180px;
  overflow: hidden;
  background: #f0f0f0;
}

.card-image {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  transition: transform 0.5s ease;
  position: relative;
}

.card-image::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  opacity: 0.7;
  transition: opacity 0.3s ease;
}

.game-card:hover .card-image {
  transform: scale(1.05);
}

.card-content {
  padding: 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-title {
  font-size: 1.5rem;
  color: #333;
  margin-bottom: 10px;
}

.card-description {
  color: #666;
  line-height: 1.6;
  margin-bottom: 20px;
  flex: 1;
}

.play-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  text-decoration: none;
  border-radius: 30px;
  font-weight: 500;
  transition: all 0.3s ease;
  align-self: flex-start;
}

.play-button:hover {
  transform: translateX(5px);
  box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.arrow-icon {
  transition: transform 0.3s ease;
}

.play-button:hover .arrow-icon {
  transform: translateX(3px);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 游戏卡片的交错动画效果 */
.game-card:nth-child(2) {
  animation-delay: 0.1s;
}

.game-card:nth-child(3) {
  animation-delay: 0.2s;
}

/* 为div类型的按钮添加鼠标指针样式 */
.play-button {
  cursor: pointer;
}
</style>